//
//  FocusDoctorTableViewCell.m
//  QuickCure
//
//  Created by 凉气的Mac on 16/9/12.
//  Copyright © 2016年 haoge. All rights reserved.
//

#import "FocusDoctorTableViewCell.h"

#import "FocusDoctorViewButton.h"

#import "FocusDoctorModel.h"

#import <UIImageView+WebCache.h>

@interface FocusDoctorTableViewCell ()

/**
 *  手术按钮
 */
@property(nonatomic,strong) FocusDoctorViewButton *operationBtn;

/**
 *  鲜花按钮
 */
@property(nonatomic,weak) FocusDoctorViewButton *flow;


/**
 *  锦旗
 */
@property(nonatomic,weak) FocusDoctorViewButton *banner;


@end

@implementation FocusDoctorTableViewCell


-(NSMutableArray *)btnArray{

    if (_btnArray == nil) {
        
        _btnArray = [NSMutableArray array];
        
    }
    
    return _btnArray;
}


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{

    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self setupUI];
        
    }
    
    return self;
}

#pragma mark --
#pragma mark --设置界面
-(void)setupUI{
    
    //医生头像
    UIImageView *doctorIcon = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"illness_img_person.png"]];
    
    self.doctorIcon = doctorIcon;
    
    doctorIcon.layer.cornerRadius = 40;
    
    doctorIcon.clipsToBounds = YES;
    
    [self.contentView addSubview:doctorIcon];
    
    [doctorIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.left.equalTo(self.contentView).offset(15);
        
        make.bottom.equalTo(self.contentView).offset(-15);
        
        make.width.height.equalTo(@80);
    }];
    
    //医生名字
    UILabel *nameLabel = [[UILabel alloc]init];
    
    self.nameLabel = nameLabel;
    
    [self.contentView addSubview:nameLabel];
    
   // nameLabel.text = @"王医生";
    
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.contentView).offset(20);
        
        make.left.equalTo(doctorIcon.mas_right).offset(10);
        
    }];
    
    //医生职位
    UILabel *positionLabel = [[UILabel alloc]init];
    
    self.positionLabel = positionLabel;
    
    [self.contentView addSubview:positionLabel];
    
   // positionLabel.text = @"副主任医师";
    
    positionLabel.font = [UIFont systemFontOfSize:15];
    
    positionLabel.textColor = [UIColor colorWithWhite:0.702 alpha:1.000];
    
    [positionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.equalTo(nameLabel);
        
        make.left.equalTo(nameLabel.mas_right).offset(10);
        
    }];
    
    //所属医院
    UILabel *hospitalLabel = [[UILabel alloc]init];
    
    self.hospitalLabel = hospitalLabel;
    
    [self.contentView addSubview:hospitalLabel];
    
    //hospitalLabel.text = @"上海长征医院";
    
    hospitalLabel.font = [UIFont systemFontOfSize:15];
    
    hospitalLabel.textColor = [UIColor colorWithWhite:0.702 alpha:1.000];
    
    [hospitalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(nameLabel.mas_bottom).offset(10);
        
        make.left.equalTo(nameLabel);
        
        make.right.equalTo(self.contentView).offset(-90);
        
    }];

    //匹配度背景
    UIImageView *matchImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"pipeidu"]];
    
    self.matchImageView = matchImageView;
    
    [self.contentView addSubview:matchImageView];
    
    [matchImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.contentView).offset(-3);
        
        make.right.equalTo(self.contentView).offset(-35);
        
        make.width.equalTo(@50);
        
        make.height.equalTo(self.contentView).multipliedBy(0.6);
        
      
    }];
    
    UILabel *matchTitle = [[UILabel alloc]init];
    matchTitle.text = @"匹配度";
    
    matchTitle.font = kFONT14;
    
    matchTitle.textColor = [UIColor whiteColor];
    
    [matchImageView addSubview:matchTitle];
    
    [matchTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.contentView).offset(8);
        
        make.centerX.equalTo(matchImageView);
        
    }];
    
    UILabel *matchLabel = [[UILabel alloc]init];
    
    self.matchLabel = matchLabel;
    
    matchLabel.text = @"99%";
    
    matchLabel.textAlignment = NSTextAlignmentCenter;
    
    matchLabel.font = kFONT14;
    
    matchLabel.textColor = [UIColor whiteColor];
    
    [matchImageView addSubview:matchLabel];
    
    [matchLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(matchTitle.mas_bottom).offset(5);
        
        make.centerX.equalTo(matchImageView);
        
    }];
    

    //手术按钮
    FocusDoctorViewButton *operationBtn = [self addBtnWithImage:[UIImage imageNamed:@"yuyueliang"]];
    
    self.operationBtn = operationBtn;
    
    //鲜花按钮
    FocusDoctorViewButton *flow = [self addBtnWithImage:[UIImage imageNamed:@"xianhua"]];
    
    self.flow = flow;
    
    [flow mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.hospitalLabel.mas_bottom);
        
        make.height.equalTo(@30);
        
        make.width.equalTo(@40);
        
        make.left.equalTo(operationBtn.mas_right).offset(10);
        
        
    }];
    
    
    //锦旗按钮
    FocusDoctorViewButton *banner = [self addBtnWithImage:[UIImage imageNamed:@"jinqi"]];
    
    self.banner = banner;
    
    [banner mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.hospitalLabel.mas_bottom);
        
        make.height.equalTo(@30);
        
        make.width.equalTo(@40);
        
        make.left.equalTo(flow.mas_right).offset(10);
        
        
    }];

    
    

}


-(FocusDoctorViewButton *)addBtnWithImage:(UIImage *)image{

    FocusDoctorViewButton *button = [[FocusDoctorViewButton alloc]init];
    
    [self.btnArray addObject:button];
    
    [button setTitle:@"34" forState:UIControlStateNormal];
    
    [self.contentView addSubview:button];
    
    [button setImage:image forState:UIControlStateNormal];
    
    [button mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.hospitalLabel.mas_bottom);
        
        make.height.equalTo(@30);
        
        make.width.equalTo(@40);
        
        make.left.equalTo(self.hospitalLabel).offset(10);
        
    }];
    
    return button;
    

}


-(void)setModel:(FocusDoctorModel *)model{

    self.nameLabel.text = model.doctor_name;
    
    self.hospitalLabel.text = model.doctor_hospital_name;
    
    self.positionLabel.text = model.doctor_title_name;
    
    self.matchLabel.text = model.accuracy;

    [self.doctorIcon sd_setImageWithURL:[NSURL URLWithString:model.doctor_portrait] placeholderImage:[UIImage imageNamed:@"illness_img_person.png"]];
    
    [self.operationBtn setTitle:[NSString stringWithFormat:@"%@",model.operation_count] forState:UIControlStateNormal];
    
    [self.flow setTitle:[NSString stringWithFormat:@"%@",model.flower] forState:UIControlStateNormal];
    
    [self.banner setTitle:[NSString stringWithFormat:@"%@",model.banner] forState:UIControlStateNormal];
    
}






@end


































































